package com.ruoyi.procurementmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurementmanagement.domain.ErpWarehouseEntryProduct;
import com.ruoyi.procurementmanagement.service.IErpWarehouseEntryProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库单商品明细Controller
 *
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/procurementmanagement/product")
public class ErpWarehouseEntryProductController extends BaseController
{
    @Autowired
    private IErpWarehouseEntryProductService erpWarehouseEntryProductService;

    /**
     * 查询入库单商品明细列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpWarehouseEntryProduct erpWarehouseEntryProduct)
    {
        startPage();
        List<ErpWarehouseEntryProduct> list = erpWarehouseEntryProductService.selectErpWarehouseEntryProductList(erpWarehouseEntryProduct);
        return getDataTable(list);
    }

    @GetMapping("/listByEntry")
    public TableDataInfo listByEntry(ErpWarehouseEntryProduct erpWarehouseEntryProduct) {
        startPage();
        List<ErpWarehouseEntryProduct> list = erpWarehouseEntryProductService.selectErpWarehouseEntryProductList(erpWarehouseEntryProduct);
        return getDataTable(list);
    }

    /**
     * 导出入库单商品明细列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:product:export')")
    @Log(title = "入库单商品明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpWarehouseEntryProduct erpWarehouseEntryProduct)
    {
        List<ErpWarehouseEntryProduct> list = erpWarehouseEntryProductService.selectErpWarehouseEntryProductList(erpWarehouseEntryProduct);
        ExcelUtil<ErpWarehouseEntryProduct> util = new ExcelUtil<ErpWarehouseEntryProduct>(ErpWarehouseEntryProduct.class);
        util.exportExcel(response, list, "入库单商品明细数据");
    }

    /**
     * 获取入库单商品明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(erpWarehouseEntryProductService.selectErpWarehouseEntryProductById(id));
    }

    /**
     * 新增入库单商品明细
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:product:add')")
    @Log(title = "入库单商品明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpWarehouseEntryProduct erpWarehouseEntryProduct)
    {
        return toAjax(erpWarehouseEntryProductService.insertErpWarehouseEntryProduct(erpWarehouseEntryProduct));
    }

    /**
     * 修改入库单商品明细
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:product:edit')")
    @Log(title = "入库单商品明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpWarehouseEntryProduct erpWarehouseEntryProduct)
    {
        return toAjax(erpWarehouseEntryProductService.updateErpWarehouseEntryProduct(erpWarehouseEntryProduct));
    }

    /**
     * 删除入库单商品明细
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:product:remove')")
    @Log(title = "入库单商品明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpWarehouseEntryProductService.deleteErpWarehouseEntryProductByIds(ids));
    }
}
